package com.example.test13spring.aop.test1;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * @Author: fxy
 * @Date: 2022/02/18/11:19
 * @Description:
 */
@Component
@Aspect
public class MyAspect {
    @Before("@annotation(com.example.test13spring.aop.test1.annotation.BeforeAnnotation)")
    public int myBefore(JoinPoint pjp){
        Object objects[] = pjp.getArgs();
        for(Object o:objects){
            System.out.println(o);
        }
        System.out.println("事前通知");
        return 1;
    }

    @AfterReturning(value = "@annotation(com.example.test13spring.aop.test1.annotation.AfterAnnotation)",returning = "r")
    public int myAfterTurning(JoinPoint pjp,Object r){
        System.out.println(r);
        Object objects[] = pjp.getArgs();
        for(Object o:objects){
            System.out.println(o);
        }
        System.out.println("事后通知");
        return 1;
    }

    @Around(value ="@annotation(com.example.test13spring.aop.test1.annotation.AroundAnnotation)")
    public int myAround(ProceedingJoinPoint pjp) throws Throwable {
        Object objects[] = pjp.getArgs();
        for(Object o:objects){
            System.out.println(o);
        }
        System.out.println("service start");
        pjp.proceed();
        System.out.println("service commit");
        return 1;
    }
}
